package com.sangmo.fts.process.inventory.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.basic.validation.BankComValidator;
import com.sangmo.fts.basic.validation.SellerComValidator;
import com.sangmo.fts.basic.validation.StorageComValidator;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;


@Entity
@Table(name = "if_contract")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class IfContract extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50,required = true, index = true, unique = true)
    private String code;

    /**
     * 质权人 （银行）
     */
    @One(value = "pledgeeCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true, validators = BankComValidator.class)
    private Long pledgee;

    /**
     * 出质人 （卖方）
     */
    @One(value = "pledgorCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true, validators = SellerComValidator.class)
    private Long pledgor;

    /**
     * 监管方 （仓储企业）
     */
    @One(value = "regulatorCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true, validators = StorageComValidator.class)
    private Long regulator;

    @DataField(value = IConstants.DATA_TYPE.DATE, required = true, index = true)
    private Date signDate;

    @One(value = "pledgeeDocument", target = FileUpload.class, groups = {"IfContract.search", "IfContract.detail"})
    private Long pledgeeDoc;

    @One(value = "pledgorDocument", target = FileUpload.class, groups = {"IfContract.search", "IfContract.detail"})
    private Long pledgorDoc;

    @One(value = "regulatorDocument", target = FileUpload.class, groups = {"IfContract.search", "IfContract.detail"})
    private Long regulatorDoc;

    @DataField(index = true)
    private boolean pledgeeConfirm;

    @DataField(index = true)
    private boolean pledgorConfirm;

    @DataField(index = true)
    private boolean regulatorConfirm;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getPledgee() {
        return pledgee;
    }

    public void setPledgee(Long pledgee) {
        this.pledgee = pledgee;
    }

    public Long getPledgor() {
        return pledgor;
    }

    public void setPledgor(Long pledgor) {
        this.pledgor = pledgor;
    }

    public Long getRegulator() {
        return regulator;
    }

    public void setRegulator(Long regulator) {
        this.regulator = regulator;
    }

    public Date getSignDate() {
        return signDate;
    }

    public void setSignDate(Date signDate) {
        this.signDate = signDate;
    }

    public Long getPledgeeDoc() {
        return pledgeeDoc;
    }

    public void setPledgeeDoc(Long pledgeeDoc) {
        this.pledgeeDoc = pledgeeDoc;
    }

    public Long getPledgorDoc() {
        return pledgorDoc;
    }

    public void setPledgorDoc(Long pledgorDoc) {
        this.pledgorDoc = pledgorDoc;
    }

    public Long getRegulatorDoc() {
        return regulatorDoc;
    }

    public void setRegulatorDoc(Long regulatorDoc) {
        this.regulatorDoc = regulatorDoc;
    }

    public boolean isPledgeeConfirm() {
        return pledgeeConfirm;
    }

    public void setPledgeeConfirm(boolean pledgeeConfirm) {
        this.pledgeeConfirm = pledgeeConfirm;
    }

    public boolean isPledgorConfirm() {
        return pledgorConfirm;
    }

    public void setPledgorConfirm(boolean pledgorConfirm) {
        this.pledgorConfirm = pledgorConfirm;
    }

    public boolean isRegulatorConfirm() {
        return regulatorConfirm;
    }

    public void setRegulatorConfirm(boolean regulatorConfirm) {
        this.regulatorConfirm = regulatorConfirm;
    }
}
